What is meant by tuple in python?Give suitable example.
What is meant by tuple in python?Give suitable example.
724
28-Mar-2023
Aryan Kumar
19-Apr-2023In Python, a tuple is a collection of ordered, immutable elements. Tuples are similar to lists in Python, but the main difference is that tuples cannot be modified once they are created. Tuples are often used to store related data together and can be indexed and iterated like lists.
Tuples are often used to return multiple values from a function, since they allow for easy grouping of related data. However, since tuples are immutable, elements cannot be modified once the tuple is created.
A tuple is created using parentheses (), and elements are separated by commas. Here's an example of a tuple:
Krishnapriya Rajeev
04-Apr-2023Tuples are one of the 4 built-in data types in Python used to store connections of data. These are used to store multiple items of the same or different data types in a single variable.
Tuples are ordered, immutable, and allow duplicate values.
Tuples are ordered, hence tuple items can be indexed:
We can use len() function to find the length of the tuple:
Since tuples are immutable, we cannot add, insert, update, or delete items from a tuple.
To create a type with only one item, we need to add a comma after the item; otherwise, it won't be recognized as a tuple: